package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.service.IEwmsOutFactoryService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsOutFactoryVo;
import ewms.bo.EwmsOutFactoryQueryBo;
import ewms.bo.EwmsOutFactoryAddBo;
import ewms.bo.EwmsOutFactoryEditBo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 委外出厂Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-17
 */
@Api(value = "委外出厂控制器", tags = {"委外出厂管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/outFactory")
public class EwmsOutFactoryController extends BaseController {

    private final IEwmsOutFactoryService iEwmsOutFactoryService;

    /**
     * 查询委外出厂列表
     */
    @ApiOperation("查询委外出厂列表")
    @PreAuthorize("@ss.hasPermi('business:outFactory:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsOutFactoryVo> list(@Validated EwmsOutFactoryQueryBo bo) {
        return iEwmsOutFactoryService.queryPageList(bo);
    }

    /**
     * 导出委外出厂列表
     */
    @ApiOperation("导出委外出厂列表")
    @PreAuthorize("@ss.hasPermi('business:outFactory:export')")
    @Log(title = "委外出厂", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsOutFactoryVo> export(@Validated EwmsOutFactoryQueryBo bo) {
        List<EwmsOutFactoryVo> list = iEwmsOutFactoryService.queryList(bo);
        ExcelUtil<EwmsOutFactoryVo> util = new ExcelUtil<EwmsOutFactoryVo>(EwmsOutFactoryVo.class);
        return util.exportExcel(list, "委外出厂");
    }

    /**
     * 获取委外出厂详细信息
     */
    @ApiOperation("获取委外出厂详细信息")
    @PreAuthorize("@ss.hasPermi('business:outFactory:query')")
    @GetMapping("/{outFactoryId}")
    public AjaxResult<EwmsOutFactoryVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("outFactoryId") Long outFactoryId) {
        return AjaxResult.success(iEwmsOutFactoryService.queryById(outFactoryId));
    }

    /**
     * 新增委外出厂
     */
    @ApiOperation("新增委外出厂")
    @PreAuthorize("@ss.hasPermi('business:outFactory:add')")
    @Log(title = "委外出厂", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsOutFactoryAddBo bo) {
        return toAjax(iEwmsOutFactoryService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改委外出厂
     */
    @ApiOperation("修改委外出厂")
    @PreAuthorize("@ss.hasPermi('business:outFactory:edit')")
    @Log(title = "委外出厂", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsOutFactoryEditBo bo) {
        return toAjax(iEwmsOutFactoryService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除委外出厂
     */
    @ApiOperation("删除委外出厂")
    @PreAuthorize("@ss.hasPermi('business:outFactory:remove')")
    @Log(title = "委外出厂" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{outFactoryIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] outFactoryIds) {
        return toAjax(iEwmsOutFactoryService.deleteWithValidByIds(Arrays.asList(outFactoryIds), true) ? 1 : 0);
    }
}
